package Banking;

public class CheckAccount extends Account {
    private SavingAccount protectedBy;

    public CheckAccount(double init_balance) {
        super(init_balance);
    }

    public CheckAccount(double init_balance, SavingAccount protectedBy) {
        super(init_balance);
        this.protectedBy = protectedBy;
    }
    public boolean withdraw(double amt){
        if(balance>=amt){
            balance-=amt;
        }else{
            if(protectedBy.getBalance()>=(amt-balance)){
                protectedBy.withdraw(amt-balance);
                balance=0;
            }else{
                return false;
            }
        }
        return true;
    }
}
